﻿@using OBUCare.Core.Models;
@using OBUCare.Core.Models;
@using OBUCare.Web.Models;
@using OBUCare.Web.Infrastructure;
@model REPAIR_ORDERS
@{
    ViewBag.Title = "标签维修单补录";
    var faultModel = ViewBag.FaultViewModel as IEnumerable<ExtendedSelectListItem<DICT_TYPE_VALUE>>;
    var repair = -1;
    bool faceStatus = true;
    string faultType = ViewBag.FaultType;
    long id = 0;
    string repairTypeTxt = string.Empty;
    string spare_obu_issue_date = string.Empty;
    string spare_obu_price = string.Empty;
    string spare_obu_no = string.Empty;
    string printVisable = "none";//是否显示打印按钮
    string repairOrderID = "";//打印按钮获取的维修单ID 如果是新增 则为空
    string supplier = string.Empty;
    string specs = string.Empty;
    int? vclass = 0;
    var dateNow = DateTime.Now.ToString("yyyy-MM-dd");
    
    string agentNo = string.Empty;
    if (Model != null)
    {
        repair = Model.REPAIR_TYPE;
        faceStatus = Model.FACE_STATUS;
        id = Model.ID;
        repairTypeTxt = Model.REPAIRED_COMMENT;
        spare_obu_issue_date = Model.SPARE_OBU_ISSUE_DATE.ToString();
        spare_obu_price = Model.SPARE_OBU_PRICE.ToString();
        spare_obu_no = Model.SPARE_OBU_NO;
        supplier = Model.SUPPLIER_ID.ToString();
        specs = Model.SPEC_ID.ToString();
        printVisable = "inline"; //如果是编辑 则显示打印按钮
        repairOrderID = Model.ID.ToString();//如果是编辑 则赋值
        vclass = Model.VEHICLE_CLASS == null ? 0 : Model.VEHICLE_CLASS - 1;
        agentNo = Model.AGENT_NO;
    }
    string actionName = ViewBag.ActionName;

    string faultTxt = ViewBag.FaultTxt;
    ObuDropDownListHlper ddlHelper = new ObuDropDownListHlper();
    var operatorInfo = UIUtility.GetCurrentUser();

    var menuNames = UIUtility.getMenuName(Request.RawUrl);

    string AgentNo = UIUtility.getAgentByModule(operatorInfo, menuNames.ToString());
}
<link href="~/Content/tableCss.css" rel="stylesheet" type="text/css" />
<div>
</div>
<table>
    <tr>
        <td>
            <font color="#4fb82c" class="txt14_24">标签维修单补录&gt;&gt;</font>
        </td>
    </tr>
    <tr>
        <td>
            @using (Html.BeginForm(actionName, "RepairOrders", FormMethod.Post, new { @id = "form_id" }))
            {
                @Html.ValidationSummary(true)
                @Html.Hidden("AgentNo", @AgentNo)
                @Html.Hidden("ID", @id)
                <div id="divObuContainer">
                    <br />
                    <img src="@Url.Content("~/Content/images/blueline1.png")" width="805" height="21">
                    <br />
                    <center>
                        <h1>
                            基本信息</h1>
                    </center>
                    <br />
                    <img src="@Url.Content("~/Content/images/blueline1.png")" width="805" height="21">
                    <br />
                    <!--动态加载标签基本信息的div容器-->
                    <div id="divObubaseInfoContainer" style="width: 100%">
                        <div style="width: 100%">
                            <div>
                                <table style="width: 100%">
                                    <tr>
                                        <td colspan="4">
                                        </td>
                                    </tr>
                                    <tr>
                                        <td width="20%">
                                            受理营业厅：
                                        </td>
                                        <td width="30%">
                                            @Html.Telerik().DropDownList().ClientEvents(events => events.OnLoad("drop_onload")).Name("Agent").HtmlAttributes(new { @style = "Width:210px;" }).DataBinding(binding => binding.Ajax().Select("_GetAgent", "RepairOrders", new { AgentType = "全部", AgentNo = AgentNo }))
                                        </td>
                                        <td width="20%">
                                            厂家：
                                        </td>
                                        <td width="30%">
                                    @*         @Html.Telerik().DropDownList().Name("Supplier").ClientEvents(events => events.OnChange("supplier_onchange")).BindTo(ddlHelper.GetSuppliers(UIConstants.AllItems, false))*@
                                            @Html.Telerik().DropDownList().Name("Supplier").BindTo(ddlHelper.GetSuppliers(supplier, false)).CascadeTo("Specs")
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            标签型号：
                                        </td>
                                        <td>
               @*                               @Html.Telerik().DropDownList().Name("Specs").HtmlAttributes(new { @style = "width:210px;" }).ClientEvents(events => events.OnChange("specs_onload"))*@
                                            @Html.Telerik().DropDownList().Name("Specs").HtmlAttributes(new { @style = "Width:230px;" }).DataBinding(binding => binding.Ajax().Select("_GetSpecs", "RepairOrders")).ClientEvents(events => events.OnDataBound("specs_OnDataBound")) 
                                        </td>
                                        <td>
                                            标签号：
                                        </td>
                                        <td>
                                            @Html.EditorFor(m => m.OBU_NO)&nbsp<span style="color: Red;">*</span>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            车牌号：
                                        </td>
                                        <td>
                                            @Html.EditorFor(m => m.VEHICLE_PLATE_NO)
                                        </td>
                                        <td>
                                            车型：
                                        </td>
                                        <td>
                                            @*@Html.EditorFor(m => m.VEHICLE_CLASS)*@
                                            @Html.Telerik().DropDownList().Name("VEHICLE_CLASS").ClientEvents(events => events.OnLoad("vclass_onchange"))
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            客户编号：
                                        </td>
                                        <td>
                                            @Html.EditorFor(m => m.USER_NO)
                                            @Html.ValidationMessageFor(model => model.USER_NO)
                                        </td>
                                        <td>
                                            发行日期：
                                        </td>
                                        <td>
                                            @if (Model == null)
                                            {
                                                @Html.Telerik().DatePickerFor(model => model.REGISTER_DATE).Value(DateTime.Now.ToShortDateString()).OpenOnFocus(true).ShowButton(false).Format(UIConstants.DateFormatString).ClientEvents(events => events.OnChange("DateTimePicker_onChange"))
                                            }
                                            else
                                            { 
                                                @Html.Telerik().DatePicker().Name("REGISTER_DATE_UI").Value(Model.REGISTER_DATE).OpenOnFocus(true).ShowButton(false).Format(UIConstants.DateFormatString).ClientEvents(events => events.OnChange("DateTimePicker_onChange"))
                                            }
                                            &nbsp<span style="color: Red;">*</span>
                                            @Html.HiddenFor(model => model.REGISTER_DATE)
                                            @if (Model == null)
                                            {
                                                @Html.ValidationMessageFor(model => model.REGISTER_DATE)
                                            }
                                            else
                                            {
                                                @Html.ValidationMessage("REGISTER_DATE_UI")                                                                    
                                            }
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            所有人：
                                        </td>
                                        <td>
                                            @Html.EditorFor(m => m.OWNER_NAME)
                                        </td>
                                        <td>
                                        </td>
                                        <td>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            <div>
                                <img src="@Url.Content("~/Content/images/blueline1.png")" width="805" height="21">
                            </div>
                        </div>
                    </div>
                    <div>
                        <table>
                            <tr>
                                <td width="20%">
                                    @Html.LabelFor(model => model.MOBILE_TEL_NO)
                                </td>
                                <td width="30%">
                                    @Html.EditorFor(model => model.MOBILE_TEL_NO)&nbsp<span style="color: Red;">*</span>
                                    @Html.ValidationMessageFor(model => model.MOBILE_TEL_NO)
                                </td>
                                <td width="20%">
                                    @Html.LabelFor(model => model.TEL_NO)
                                </td>
                                <td width="30%">
                                    @Html.EditorFor(model => model.TEL_NO)
                                    @Html.ValidationMessageFor(model => model.TEL_NO)
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    @Html.LabelFor(model => model.MAX_PRICE)
                                </td>
                                <td>
                                    @Html.EditorFor(model => model.MAX_PRICE)&nbsp<span style="color: Red;">*</span>
                                    @Html.ValidationMessageFor(model => model.MAX_PRICE)
                                </td>
                                <td>
                                    @Html.LabelFor(model => model.REPORTER)
                                </td>
                                <td>
                                    @Html.EditorFor(model => model.REPORTER)&nbsp<span style="color: Red;">*</span>
                                    @Html.ValidationMessageFor(model => model.REPORTER)
                                </td>
                            </tr>
                            <tr>
                                <td colspan="4">
                                    <img src="@Url.Content("~/Content/images/blueline1.png")" width="805" height="21">
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    @Html.Label("lblOrderFalut", "故障描述")
                                    @* @Html.LabelFor(model => model.OrderFalut)
                        @Html.ValidationMessageFor(model => model.OrderFalut)*@ @*@Html.HiddenFor(model => model.OrderFalut, new { width = "0px" })*@
                                </td>
                                <td colspan="3">
                                    @Html.Partial("_FaultCheckBoxList", faultModel)
                                </td>
                            </tr>
                            <tr>
                                <td colspan="4">
                                    <img src="@Url.Content("~/Content/images/blueline1.png")" width="805" height="21">
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    @Html.LabelFor(model => model.FACE_STATUS)
                                </td>
                                <td colspan="3">
                                    @Html.RadioButtonFor(model => model.FACE_STATUS, false, new { @id = "FACE_STATUS0", @checked = "checked" })
                                    @Html.Label("FACE_STATUS0", "外观完好")
                                    @Html.RadioButtonFor(model => model.FACE_STATUS, true, new { @id = "FACE_STATUS1"})
                                    @Html.Label("FACE_STATUS1", "外观有故障")
                                    @Html.ValidationMessageFor(model => model.FACE_STATUS)
                                </td>
                            </tr>
                            <tr>
                                <td colspan="4">
                                    <img src="@Url.Content("~/Content/images/blueline1.png")" width="805" height="21">
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    @Html.LabelFor(model => model.REPAIR_TYPE)
                                </td>
                                <td colspan="3">
                                    @*@Html.EditorFor(model => model.REPAIR_TYPE)*@
                                    @Html.Partial("_RepairType", ViewBag.RepairTypeViewModel as IEnumerable<ExtendedSelectListItem<REPAIR_TYPE>>)
                                    @Html.ValidationMessageFor(model => model.REPAIR_TYPE)
                                </td>
                            </tr>
                            <tr>
                                <td colspan="4">
                                    <img src="@Url.Content("~/Content/images/blueline1.png")" width="805" height="21">
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    @Html.Label("isNeedSpareObu", "是否需要备用标签:")
                                </td>
                                <td colspan="3">
                                    @Html.RadioButton("radisNeedSpareObu", "1", new { @id = "radisNeedSpareObuY" })
                                    @Html.Label("radisNeedSpareObuY", "是")
                                    @Html.RadioButton("radisNeedSpareObu", "0", true, new { @id = "radisNeedSpareObuN" })
                                    @Html.Label("radisNeedSpareObuY", "否")
                                </td>
                            </tr>
                            <tr>
                                <td colspan="4">
                                    <table id="tbSpare" style="display: none">
                                        <tr>
                                            <td colspan="4">
                                                <img src="@Url.Content("~/Content/images/blueline1.png")" width="805" height="21">
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                @Html.LabelFor(model => model.SPARE_OBU_NO)
                                            </td>
                                            <td>
                                                @Html.EditorFor(model => model.SPARE_OBU_NO)
                                                @Html.ValidationMessageFor(model => model.SPARE_OBU_NO)
                                            </td>
                                            <td>
                                                @Html.LabelFor(model => model.SPARE_OBU_PRICE)
                                            </td>
                                            <td>
                                               
                                                @if (actionName == "EditNewOrderWithNoBaseInfo")
                                                {
                                                @Html.DisplayFor(model=>model.SPARE_OBU_PRICE) <span>(元)</span>
                                                }
                                                else
                                                { 
                                                 @Html.EditorFor(model => model.SPARE_OBU_PRICE)<span>(元)</span>
                                                    @Html.ValidationMessageFor(model => model.SPARE_OBU_PRICE)
                                                }
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                @Html.LabelFor(model => model.SPARE_OBU_ISSUE_DATE)
                                            </td>
                                            <td>
                                                @if (Model == null)
                                                {
                                                    @Html.Telerik().DatePickerFor(m => m.SPARE_OBU_ISSUE_DATE).Value(DateTime.Now.ToShortDateString()).OpenOnFocus(true).ShowButton(false).Format(UIConstants.DateFormatString)
                                                }
                                                else
                                                {
                                                    @Html.Telerik().DatePicker().Name("SPARE_OBU_ISSUE_DATE_UI").Value(Model.SPARE_OBU_ISSUE_DATE).OpenOnFocus(true).ShowButton(false).Format(UIConstants.DateFormatString)
                                                }
                                                &nbsp<span style="color: Red;">*</span>
                                                @Html.HiddenFor(model => model.SPARE_OBU_ISSUE_DATE)
                                                @if (Model == null)
                                                {
                                                    @Html.ValidationMessageFor(model => model.SPARE_OBU_ISSUE_DATE)
                                                }
                                                else
                                                {
                                                    @Html.ValidationMessage("SPARE_OBU_ISSUE_DATE_UI")                                                                    
                                                }
                                            </td>
                                            <td>
                                            </td>
                                            <td>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="4">
                                    <img src="@Url.Content("~/Content/images/blueline1.png")" width="805" height="21">
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    @Html.LabelFor(model => model.REPORT_DATE)
                                </td>
                                <td>
                                    @*@Html.Telerik().DatePickerFor(model => model.REPORT_DATE).OpenOnFocus(true).ShowButton(false).Value(DateTime.Now.ToString("yyyy-MM-dd"))*@
                                    @if (Model == null)
                                    {
                                        @Html.Telerik().DatePickerFor(model => model.REPORT_DATE).Value(DateTime.Now.ToShortDateString()).OpenOnFocus(true).ShowButton(false).Format(UIConstants.DateFormatString)
                                    }
                                    else
                                    {
                                        @Html.Telerik().DatePicker().Name("REPORT_DATE_UI").Value(Model.REPORT_DATE).OpenOnFocus(true).ShowButton(false).Format(UIConstants.DateFormatString)
                                    }
                                    &nbsp<span style="color: Red;">*</span>
                                    @Html.HiddenFor(model => model.REPORT_DATE)
                                    @if (Model == null)
                                    {
                                        @Html.ValidationMessageFor(model => model.REPORT_DATE)
                                    }
                                    else
                                    {
                                        @Html.ValidationMessage("REPORT_DATE_UI")                                                                    
                                    }
                                </td>
                                <td>
                                </td>
                                <td>
                                </td>
                            </tr>
                        </table>
                    </div>
                    <br />
                    <img src="@Url.Content("~/Content/images/blueline1.png")" width="805" height="21">
                    <br />
                    <div>
                        @if (Model == null)
                        {
                            <input type="button" id="submit" value=" " style="background-image: url(@Url.Content("~/Content/images/button_up.gif")); width:200;height:30" />
                        }
                        else
                        { 
                            <input type="submit" id="submitbtn" value=" " style="background-image: url(@Url.Content("~/Content/images/button_up.gif")); width:200;height:30" />
                        }
                        <input type="button" style="display:@printVisable;" onclick="window.open('/RepairOrders/Print/@repairOrderID')" value="打印" />
                    </div>
                </div>
            }
        </td>
    </tr>
</table>
<div id="divPrintContainer">
</div>
<script type="text/javascript">
    function drop_onload(e){
    var drop = $('#Agent').data('tDropDownList');
    $.post("/RepairOrders/_GetAgentCR",{"AgentType":"全部","AgentNo":"@AgentNo"},function(data){
                drop.dataBind(data);
                drop.select(0);
                if("@AgentNo" != ""){
                    drop.disable();
                }
    })
    }

    function vclass_onchange(e){
    var VehicleClass = $('#VEHICLE_CLASS').data('tDropDownList');
    $.post("/RepairOrders/_GetVehicleClass",{},function(data){
                VehicleClass.dataBind(data);
                var vclass ="@vclass";
                VehicleClass.select(vclass);
    })
    }

    function supplier_onchange(e){
    //debugger;
    var supplier = $('#Supplier').data('tDropDownList');
    var specs = $('#Specs').data('tDropDownList');
     $.post("/RepairOrders/_GetSpecs",{"supplierID":supplier.value()},function(data){
                specs.dataBind(data);
                specs.select(0);
    })
    }

    function specs_onload(e){
    var supplier = $('#Supplier').data('tDropDownList');
    var specs = $('#Specs').data('tDropDownList');
    $.post("/RepairOrders/_GetSpecs",{"supplierID":supplier.value()},function(data){
                specs.dataBind(data);
                specs.select(0);})
    }

    var spec = "@specs";
    function specs_OnDataBound(e)
    {
        var specs = $('#Specs').data('tDropDownList');
        if(spec!=null)
        {
            specs.value(spec);
            spec=null;
        }
        
    }

    function DateTimePicker_onChange(e){
        var dateTimePicker = $(this).data('tDateTimePicker'); // $(this) is equivalent to $('#DateTimePicker')
        
        var value =$("#REGISTER_DATE").val();
        if(@id!=0){
         value = $("#REGISTER_DATE_UI").val();
        }
        //var previousValue = e.previousValue;
        var date_now = getDate('-');
//        var sRDate = Date.parse(value);
//        var eRDate = Date.parse(date_now);alert(sRDate+"__"+eRDate);

        var sArr = value.split("-");
        var eArr = date_now.split("-");
        var sRDate = new Date(sArr[0], sArr[1], sArr[2]);
        var eRDate = new Date(eArr[0], eArr[1], eArr[2]);
        var result = (eRDate-sRDate)/(365*24*60*60*1000);
        if(result>2){
         $("#REPAIR_TYPE3").attr("checked", "checked");
        }else{
        $("#REPAIR_TYPE2").attr("checked", "checked");
        }
        
    }


    $(function () {
        var drop = $('#Agent').data('tDropDownList'); 
        if(!"@agentNo".StringIsNullOrEmpty()){
            $.post("/RepairOrders/_GetAgentReturnIndex",{AgentNo:"@agentNo"},function(data){
            drop.select(data.Index);
            })
        }

        @*var supplier = "@supplier";
        if("@supplier".length != 0){
          var cs = $('#Supplier').data('tDropDownList');
           $.post("/RepairOrders/_GetSupplier",{"supplierID":supplier},function(data){
                cs.select(data.Index);})
        }
        var specs = "@specs";
        if("@specs".length != 0){
          var sp = $('#Specs').data('tDropDownList');/*supplierID specsID*/
           $.post("/RepairOrders/_GetSpecsReturnIndex",{"supplierID":supplier,"specsID":specs},function(data){
                sp.dataBind(data.Source);
                sp.select(data.Index);})
        }*@

        var faults = "@faultType".split(',');
        for (var i = 0; i < faults.length; i++) {
            $("#orderFault" + faults[i]).attr("checked", "checked");
        }
        $("#orderFaultReMark").val("@faultTxt");
        $("#REPAIRED_COMMENT").val("@repairTypeTxt");
        if ("@faceStatus" == "False") {
            $("#FACE_STATUS0").attr("checked", "checked");
        }
        else {
            $("#FACE_STATUS1").attr("checked", "checked");
        }
        var repair =@repair;
        if(repair != -1){
            $("#REPAIR_TYPE"+repair).attr("checked", "checked");
        }
        if("@actionName"=="NewOrderWithNoBaseInfo")
        {
        $("#USER_NO").val("00000000000000");
        $("#OBU_NO").val("0000000000000000");
        }
        //debugger;
         if ( "@spare_obu_price".length != 0 || "@spare_obu_no".length != 0 ||"@spare_obu_issue_date".length!=0) {
            $("#tbSpare").attr("style", "display:inline");
            $("#radisNeedSpareObuY").attr("checked","checked");
            document.getElementById("radisNeedSpareObuN").disabled=true;
        }else if("@actionName"=="EditNewOrderWithNoBaseInfo")
        {
          document.getElementById("radisNeedSpareObuN").disabled=true;
          document.getElementById("radisNeedSpareObuY").disabled=true;
        }
        else
        {
          document.getElementById("radisNeedSpareObuN").disabled=false;
          document.getElementById("radisNeedSpareObuY").disabled=false;
        }
       
        $("#radisNeedSpareObuN").click(function () {
            $("#SPARE_OBU_ISSUE_DATE_UI").val("");
            $("#SPARE_OBU_ISSUE_DATE").val("");
            $("#SPARE_OBU_PRICE").val("");
            $("#SPARE_OBU_NO").val("");
            $("#tbSpare").attr("style", "display:none");
        })
        $("#radisNeedSpareObuY").click(function () {
            $("#SPARE_OBU_ISSUE_DATE_UI").val("@dateNow");
            $("#SPARE_OBU_ISSUE_DATE").val("@dateNow");
            $("#SPARE_OBU_PRICE").val("300");
            $("#tbSpare").attr("style", "display:inline");
        })

        $("#submit").click(function () {
            var obu_val = $("#OBU_NO").val();
            if (obu_val.length != 16) {
                alert("请输入16位标签号！");
                return false;
            }

            var labels = $("label[name=lab]");
            for (var i = 0; i < labels.length; i++) {
                var faultContent = $(labels[i]).html();

                if (faultContent == '其它') {
                    var faultFor = $(labels[i]).attr("for");
                    var checked = $("#" + faultFor).attr("checked");
                    var orderFaultReMark = $("#orderFaultReMark").val();
                    if (checked == "checked" && orderFaultReMark.StringIsNullOrEmpty()) {
                        alert("必须填写故障描述！"); return false;
                    }

                }
            }

            var labelstype = $("label[name=type]");
            for (var i = 0; i < labelstype.length; i++) {
                var typeContent = $(labelstype[i]).html();

                if (typeContent == '其它') {
                    var typeFor = $(labelstype[i]).attr("for");
                    var checked = $("#" + typeFor).attr("checked");
                    var orderTypeReMark = $("#REPAIRED_COMMENT").val();
                    if (checked == "checked" && orderTypeReMark.StringIsNullOrEmpty()) {
                        alert("必须填写维修类型描述！"); return false;
                    }

                }
            }

            var chk = $("#radisNeedSpareObuY").attr("checked");
            if (chk == "checked") {
                var s_obu_price = $("#SPARE_OBU_PRICE").val()
                var s_obu_issue_date = $("#SPARE_OBU_ISSUE_DATE_UI").val();
                var s_obu_issue_date1 = $("#SPARE_OBU_ISSUE_DATE").val();
                if (s_obu_price.length == 0) {
                    alert("请输入备用标签押金！"); return false;
                }
                else if (s_obu_issue_date&&s_obu_issue_date1) {
                    alert("请输入备用标签安装日期！"); return false;
                }
            }
            var reg = /^\d{4}[-\/.]\d{1,2}[-\/.]\d{1,2}$|^\d{4}[-\/.]\d{1,2}[-\/.]\d{1,2} \d{1,2}:\d{1,2}:\d{1,2}$/;
            var dpa = $("#REGISTER_DATE_UI").val();
            var dpa1 = $("#REGISTER_DATE").val();
            if (dpa == ""&&dpa1=="") {
                alert("请输入发行日期！"); return false;
            }
            else {
                if (!reg.test(dpa)&&!reg.test(dpa1)) {

                    alert("输入的发行日期不合法！"); return false;
                }
            }
            var dpr = $("#REPORT_DATE_UI").val();
            var dpr1 = $("#REPORT_DATE").val();
            if (dpr == ""&&dpr1!="") {
                alert("请输入受理日期！"); return false;
            }
            else {
                if (!reg.test(dpr)&&!reg.test(dpr1)) {

                    alert("输入的受理日期不合法！"); return false;
                }
            }
            //debugger;
             var form = $("#form_id");
            dataString = form.serialize();
            $.ajax({
                type: "POST",
                url: form.attr('action'),
                data: dataString,
                cache: false,
                dataType: "json",
                success: function (data) {
                    var url = "";
                    if (data.userNO != "")
                        url = "/Transaction/Index/?orderUserNo=" + data.userNO;
                    else
                        url = "/RepairOrders/List/";

                    if (data.Success) {
                        if (confirm("提交成功，是否打印?")) {
                            //printOrder(data.id, url);
                             window.open("/RepairOrders/Print/" + data.id + "?userNO=" + data.userNO);
                              window.location.href = url;
                        }
                        else {
                            window.location.href = url;
                        }                }
                    else {
                        alert('提交失败：' + data.ErrorMsg)
                    }
                } ,
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    var err = XMLHttpRequest + "<br />" + textStatus + "<br /> 验证" + errorThrown;
                    alert(err);
                }
            });
        })

    });

//    function checkExitRepair()
//    {
//   debugger;
//    var obuNo=$.trim( $("#OBU_NO").val());
//    alert(obuNo);
//    if(obuNo!="0000000000000000")
//    {
//     $.post("/RepairOrders/checkExitObuRepair",{obu_no:obuNo},function(data){
//        if(data.Success==false)
//        {
//           alert(data.message);
//           return false;
//        }
//        else
//        {
//           $('#form_id').submit();
//        }
//            }) ;
//    }
//    }

    function getDate(separator) {
        var d, s = "";
        d = new Date();
        s += d.getFullYear() + separator;
        s += (d.getMonth() + 1) + separator;
        s += d.getDate();
        return s;
    }
   

   //动态加载打印页面，并打印
    function printOrder(id,url) {
        var purl = '/RepairOrders/Print/' + id;
        
        $('#divPrintContainer').load(purl, function (response, status) {
            debugger
            //alert(status);
            if (status == "success") {
                $('#divPrintContainer').show();
                printpage('divPrintContainer');
                //alert("打印成功");
                //window.location.href = url;
            }
            else {                
                alert("打印失败");
            }
        })
        
    }
</script>
@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}
